﻿using System;
using System.Collections.Generic;
using System.Reflection;

namespace ProjectDanmaku.Util
{
    public static class ReflectionUtility
    {
        public static MethodInfo GetInstanceMethodByParamType(
            Type type, string methodName, params Type[] paramTypes)
        {
            var method = type.GetMethod(methodName);
            if (method == null)
                return default;

            if (method.GetParameters().Length != paramTypes.Length)
                return null;

            for (var i = 0; i < paramTypes.Length; i++)
            {
                var paramType = paramTypes[i];
                var parameter = method.GetParameters()[i];

                if (parameter.ParameterType != paramType)
                {
                    return null;
                }
            }

            return method;
        }
    }
}